//
//  YSpersonalConreoller.m
//  WHISPER
//
//  Created by lanou3g on 15/12/22.
//  Copyright © 2015年 王艳苹. All rights reserved.


#import "YSpersonalConreoller.h"
#import "personalCell.h"
#import "anotherCell.h"
#import "YPNetWorking.h"
#import "YPMakeURL.h"
#import "personalCell.h"
#import "anotherCell.h"
#import "YPPerson.h"
#import "YPPersonModel.h"
#import "UIImageView+WebCache.h"

#import "YPWebViewVC.h"

@interface YSpersonalConreoller ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *table;

@property (nonatomic,strong) YPPerson *person;
@property (nonatomic,strong) NSMutableArray *listArr;

@end

@implementation YSpersonalConreoller

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];
    self.table = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:_table];
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [[YPNetWorking shareNetWorking] getDictWithURL:[YPMakeURL shareMakeURL].userURL dict:[[YPMakeURL shareMakeURL] makeUserDicWithUid:self.uid] success:^(NSDictionary *dic) {
        self.person = [[YPPerson alloc]init];
        [self.person setValuesForKeysWithDictionary:dic[@"data"][@"userinfo"]];
        self.table.tableHeaderView = [self setHeadView];
        [self.table reloadData];
    } fail:^(NSError *err) {
        
    }];
}

-(NSMutableArray *)listArr{
    if (_listArr == nil) {
        _listArr = @[].mutableCopy;
    }
    return _listArr;
}

-(UIView *)setHeadView{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 200)];
    view.backgroundColor = [UIColor redColor];
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    [imageV sd_setImageWithURL:[NSURL URLWithString:self.person.coverimg] placeholderImage:[UIImage imageNamed:@"16.png"]];
    [view addSubview:imageV];
    UIImageView *imageV1 = [[UIImageView alloc]initWithFrame:CGRectMake(50, 35, 70, 70)];
    imageV1.backgroundColor = [UIColor redColor];
    imageV1.layer.cornerRadius = imageV1.frame.size.width / 2;
    imageV1.clipsToBounds = YES;
    imageV1.layer.borderWidth = 3.0f;
    imageV1.layer.borderColor = [UIColor whiteColor].CGColor;
    [imageV1 sd_setImageWithURL:[NSURL URLWithString:self.person.icon] placeholderImage:[UIImage imageNamed:@"16.png"]];
    [imageV addSubview:imageV1];
    UIButton *but = [UIButton buttonWithType:UIButtonTypeSystem];
    but.frame = CGRectMake(CGRectGetMinX(imageV1.frame), CGRectGetMaxY(imageV1.frame) + 20, CGRectGetWidth(imageV1.frame), 20);
    but.backgroundColor = [UIColor greenColor];
    [but setTitle:@"+关注" forState:UIControlStateNormal];
    [but setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [imageV addSubview:but];
    UIImageView *imageV2 = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageV1.frame) + 20, CGRectGetMinY(imageV1.frame) + 20, 20, 20)];
    imageV2.layer.cornerRadius = imageV2.frame.size.width / 2;
    imageV2.clipsToBounds = YES;
    if (self.person.gender == 1) {
        imageV2.image = [UIImage imageNamed:@"Male"];
    }else{
       imageV2.image = [UIImage imageNamed:@"Female"]; 
    }
    [imageV addSubview:imageV2];
    
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageV2.frame) + 10, CGRectGetMinY(imageV2.frame) - 5, 180, 30)];
    name.text = self.person.uname;
    [imageV addSubview:name];
    
    UILabel *content = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(imageV2.frame), CGRectGetMaxY(imageV2.frame) + 20, 190, 20)];
    if ([self.person.desc isEqualToString:@""]) {
        content.text = @"这家伙很懒啥也没留下";
    }else{
        content.text = self.person.desc;
    }
    content.font = [UIFont systemFontOfSize:14];
    [imageV addSubview:content];
    
    UIButton *but1 = [UIButton buttonWithType:UIButtonTypeSystem];
    but1.backgroundColor = [UIColor blueColor];
    but1.frame = CGRectMake(CGRectGetMaxX(content.frame) + 10,CGRectGetMaxY(content.frame) + 40, 30, 30);
    but1.layer.cornerRadius = but1.frame.size.width / 2;
    but1.clipsToBounds = YES;
    [but1 setBackgroundImage:[UIImage imageNamed:@"fans"] forState:UIControlStateNormal];
    [imageV addSubview:but1];
    
    UIButton *but2 = [UIButton buttonWithType:UIButtonTypeSystem];
    but2.frame = CGRectMake(CGRectGetMinX(but1.frame) - 40, CGRectGetMinY(but1.frame), 30, 30);
    but2.backgroundColor = [UIColor yellowColor];
    but2.layer.cornerRadius = but2.frame.size.width / 2;
    but2.clipsToBounds = YES;
    [but2 setBackgroundImage:[UIImage imageNamed:@"guanzhu"] forState:UIControlStateNormal];
    [imageV addSubview:but2];
    return view;
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listArr.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *str = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    return cell;
}

-(void)backAction{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
